.PHONY: unit_test joint_test gen clean_gen

PWD = $(shell pwd)

APPS = $(wildcard apps/*)
define MAKE_UNIT_TEST
  $(subst apps/,,$(1))_unit_test:
	cd $(1) && make \
		PWD="$${PWD}" \
		PROJECT_DIR="$${PWD}/$(1)" \
		unit_test
endef
$(foreach v, $(APPS), $(eval $(call MAKE_UNIT_TEST,$(v))))
unit_test: $(foreach v, $(APPS), $(subst apps/,,$(v))_unit_test)

define MAKE_JOINT_TEST
  $(subst apps/,,$(1))_joint_test:
	cd $(1) && make \
		PWD="$${PWD}" \
		PROJECT_DIR="$${PWD}/$(1)" \
		joint_test
endef
$(foreach v, $(APPS), $(eval $(call MAKE_JOINT_TEST,$(v))))
joint_test: $(foreach v, $(APPS), $(subst apps/,,$(v))_joint_test)

TPL_DIR = ${PWD}/crates/meta_template
define MAKE_GEN
  $(subst apps/,,$(1))_gen:
	cd $(1) && make -j12 \
		TPL_DIR="$${TPL_DIR}" \
		PROJECT_NAME=$(subst apps/,,$(1)) \
		gen
endef
$(foreach v, $(APPS), $(eval $(call MAKE_GEN,$(v))))
gen: $(foreach v, $(APPS), $(subst apps/,,$(v))_gen)

define MAKE_CLEAN_GEN
  $(subst apps/,,$(1))_clean_gen:
	cd $(1) && rm -rf gen
endef
$(foreach v, $(APPS), $(eval $(call MAKE_CLEAN_GEN,$(v))))
clean_gen: $(foreach v, $(APPS), $(subst apps/,,$(v))_clean_gen)
	rm -rf ${TPL_DIR}/temp
